<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset=utf8>
</head>
<body>
    <script>
      var str = new String('aaaasasda');

      var str = String(true);
      var str = 'I am jingjing,I love you,do yao zao?上海!';

      console.log(str);
      console.log(typeof str);
      console.log(str.constructor);

      document.write('str长度:'+str.length+'<br>');
      document.write(str + '<br>');
      //加粗
      document.write('加粗:'+str.bold()+'<br>');
      //锚点
      document.write('锚点:'+str.anchor('p1')+'<br>');

      //charAt
      document.write('charAt:'+str.charAt(2)+'<br>');
      document.write('类数组语法:'+str[2]+'<br>');

      document.write('<hr>');
      //indexOf 返回第一次小狐仙指定字串的位置,未找到则返回-1
      document.write('indexOf:'+str.indexOf('you')+'<br>');
      document.write('indexOf:'+str.indexOf('kkk')+'<br>');
      //lastIndexOf返回最后一次出现指定字串的位置,未找到则返回-1
      document.write('lastIndexOf:'+str.lastIndexOf('you')+'<br>');
      document.write('lastIndexOf:'+str.lastIndexOf('kkk')+'<br>');
      document.write('lastIndexOf:'+str.indexOf('呵')+'<br>');

      document.write('<hr>');
      //substr(strat,length)
      //截取字符串,无指定长度,截取到尾部为止
      document.write('substr:'+str.substr(22)+'<br>');
      document.write('substr:'+str.substr(3,6)+'<br>');
      document.write('substr:'+str.substr(-3,2)+'<br>');
      //substring (start,end)
      //截取字串,从start开始到end结束,不含end,参数不能使负数
      document.write('substring:'+str.substring(22)+'<br>');
      document.write('substring:'+str.substring(3,6)+'<br>');
      document.write('substring:'+str.substring(-3,-1)+'<br>');
      //slice(start,end)
      //截取字符串,从start开始到end结束,不含end,参数可以使负数
      document.write('slice:'+str.slice(22)+'<br>');
      document.write('slice:'+str.slice(3,6)+'<br>');
      document.write('slice:'+str.slice(-3,-1)+'<br>');

      //转小写
      document.write('toLowerCase:'+str.toLowerCase+'<br>');
      //转大写
      document.write('toUpperCase:'+str.toUpperCase+'<br>');

      document.write('<hr>');

      //一下方法都支持正则参数 
      //replace()字符串替换
      document.write('replace:'+str.replace('you','你')+'<br>');
      document.write('replace:'+str.replace(/you/,'你')+'<br>');
      document.write('replace:'+str.replace(/\w/,'你')+'<br>');
      document.write('replace:'+str.replace(/\w/g,'你')+'<br>');
      document.write('replace:'+str.replace(/\d/g,'你')+'<br>');

      //match()匹配第一个匹配到的结果,不匹配返回null
      document.write('match:'+str.match('a')+'<br>');
      document.write('match:'+str.match('k')+'<br>');
      document.write('match:'+str.match(/\w{8}/)+'<br>');
      document.write('match:'+str.match('/\w{88}/')+'<br>');

      //search正则验证,匹配第一次出现的位置,不匹配则返回-1
      document.write('search:'+str.search('am')+'<br>');
      document.write('search:'+str.search(/\w{8}/)+'<br>');
      document.write('search:'+str.search(/\w{88}/)+'<br>');
      //split 把字串分割为数组(字串转数组)
      console.log(str.split());
      console.log(str.split(','));
      console.log(str.split(''));
      console.log(str.split(/[, ?]/));
      
        
    </script>
</body>
</html>